<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" type="text/css" href="../../doc/style.css" />
  <title>Shell</title>
</head>

<body>
  <table bgcolor="#000000" width="100%" cellspacing="0" cellpadding="0" border="0" class="tmenu">
    <tr>
      <td><img src="../../doc/SciTEIco.png" height="64" width="64" alt="Scintilla icon" /></td>
      <td width="100%"><font size="5">Shell - Lua library for SciTE</font></td>
    </tr>
  </table>

  <table bgcolor="#CCCCCC" width="100%" cellspacing="0" cellpadding="8" border="0" class="tmenu">
    <tr><td>
      <a href="../../doc/SciTEDoc.html">Documentation</a>&nbsp;&nbsp;
      <a href="../../doc/SciTEFAQ.html">FAQ</a>&nbsp;&nbsp;
      <a href="../../doc/SciTERegEx.html">Regular Expressions</a>&nbsp;&nbsp;
      <a href="../../doc/Scintilla/ScintillaDoc.html">Scintilla</a>&nbsp;&nbsp;
      <a href="../../doc/SciTELua.html">LUA</a>&nbsp;&nbsp;
      <a href="../../doc/SciTEDirector.html">SciTE Director</a>&nbsp;&nbsp;
      <a href="../../doc/CommandValues.html">SciTE and Scintilla Commands</a>&nbsp;&nbsp;
      <a href="../../doc/SciTE-Ru_Kernel.html">SciTE-Ru Kernel</a>&nbsp;&nbsp;
      Shell&nbsp;&nbsp;
      <a href="../Helper/SciTE.Helper.html">SciTE Helper</a>&nbsp;&nbsp;
      <a href="../../doc/Scintilla/ScintillaHistory.html">History</a>&nbsp;&nbsp;
    </td></tr>
  </table>

<h3>Description</h3>

<p>External Lua library expanding opportunities SciTE Lua Scripting Extension.</p>

<h3>DLL loading</h3>

<p>Before use of library functions it require load:</p>
<div class="example">
package.cpath = props["SciteDefaultHome"].."\\tools\\LuaLib\\?.dll;"..package.cpath<br />
-- show all paths on which SciTE will search for our library<br />
print(package.cpath)<br />
-- library loading<br />
require 'shell'<br />
-- test dll<br />
if shell then<br />
&nbsp;&nbsp;table.foreach(shell, print)<br />
end
</div>

<h3>Functions</h3>

<table width="100%" cellpadding="1" cellspacing="0" border="1">

<tr><td>
	<p class="head">
		<dfn id="msgbox">msgbox (strMessageText, [strTitle], [intOptions])</dfn>
	</p>
	<p>
		<b>Description:</b><br />
		&nbsp;&nbsp;Showing text message with buttons.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strMessageText</dfn> - text message<br />
		&nbsp;&nbsp;<dfn>strTitle</dfn> - title text of message<br />
		&nbsp;&nbsp;<dfn>intOptions</dfn> - numerical expression representing the sum of values, listed in the table.
	</p>
		<table style="margin-left:8pt;margin-top:3pt">
		<tr><th>Value</th><th>Description</th></tr>
		<tr>
		<td align="center">0</td>
		<td>Display OK button only (default)</td>
		</tr>
		<tr>
		<td align="center">1</td>
		<td>Display OK and Cancel buttons</td>
		</tr>
		<tr>
		<td align="center">2</td>
		<td>Display Abort, Retry, and Ignore buttons</td>
		</tr>
		<tr>
		<td align="center">3</td>
		<td>Display Yes, No, and Cancel buttons</td>
		</tr>
		<tr>
		<td align="center">4</td>
		<td>Display Yes and No buttons</td>
		</tr>
		<tr>
		<td align="center">5</td>
		<td>Display Retry and Cancel buttons</td>
		</tr>
		<tr>
		<td align="center">16</td>
		<td>Display Critical Message icon</td>
		</tr>
		<tr>
		<td align="center">32</td>
		<td>Display Question Message icon</td>
		</tr>
		<tr>
		<td align="center">48</td>
		<td>Display Exclamation Message icon</td>
		</tr>
		<tr>
		<td align="center">64</td>
		<td>Display Information Message icon</td>
		</tr>
		<tr>
		<td align="center">0</td>
		<td>First button is the default</td>
		</tr>
		<tr>
		<td align="center">256</td>
		<td>Second button is the default</td>
		</tr>
		<tr>
		<td align="center">512</td>
		<td>Third button is the default</td>
		</tr>
		<tr>
		<td align="center">768</td>
		<td>Fourth button is the default</td>
		</tr>
		<tr>
		<td align="center">0</td>
		<td>Application modal. The user must respond to the message box before continuing work in the current application.</td>
		</tr>
		<tr>
		<td align="center">4096</td>
		<td>System modal. On Win16 systems, all applications are suspended until the user responds to the message box. On Win32 systems, this constant provides an application modal message box that always remains on top of any other programs you may have running.</td>
		</tr>
		</table>
	<br />
	<p>
	<b>Return value:</b><br />
		&nbsp;&nbsp;Returned code to identify which button a user has selected. Values are listed in the table:
	</p>
		<table style="margin-left:8pt;margin-top:3pt">
		<tr><th>Value</th><th>Description</th></tr>
		<tr>
		<td align="center">1</td>
		<td>OK button was clicked</td>
		</tr>
		<tr>
		<td align="center">2</td>
		<td>Cancel button was clicked</td>
		</tr>
		<tr>
		<td align="center">3</td>
		<td>Abort button was clicked</td>
		</tr>
		<tr>
		<td align="center">4</td>
		<td>Retry button was clicked</td>
		</tr>
		<tr>
		<td align="center">5</td>
		<td>Ignore button was clicked</td>
		</tr>
		<tr>
		<td align="center">6</td>
		<td>Yes button was clicked</td>
		</tr>
		<tr>
		<td align="center">7</td>
		<td>No button was clicked</td>
		</tr>
		</table>
		<p><b>Example:</b></p>
		<div class="example">
		if shell.msgbox("You are sure?", "SciTE", 65) == 1 then<br />
		&nbsp;&nbsp;print("Yes")<br />
		end<br />
		</div>
	<p class="author">Authors: Midas, mimir</p>
</td></tr>

<tr><td>
	<p class="head">
		<dfn id="inputbox">inputbox(strCaptionText, strPrompt, strDefaultValue, funcCheckInput, intMinWidth)</dfn>
	</p>
	<p>
	<b>Description:</b><br />
		&nbsp;&nbsp;Display dialog box for input some text value.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strCaptionText</dfn> - the title for the dialog box. The default is <var>"InputBox"</var>.<br />
		&nbsp;&nbsp;<dfn>strPrompt</dfn> - the message to be displayed above an edit field. The default is <var>"Enter"</var>.<br />
		&nbsp;&nbsp;<dfn>strDefaultValue</dfn> - text to be displayed in the edit field. Defaults to <var>""</var> (the empty string).<br />
		&nbsp;&nbsp;<dfn>funcCheckInput</dfn> - the input-checking function. It gets the text from the edit field together with the newly received char and must return either <var>true</var> (to accept this char) or <var>false</var> (to reject it). Default value is <var>nil</var> (it means no restrictions).<br />
		&nbsp;&nbsp;<dfn>intMinWidth</dfn> - the minimal width of the edit field in average chars. The default is <var>20</var>. <b>Note</b>. The dialog box automatically changes its width to accommodate the widest field of the <var>strPrompt</var> and <var>strDefaultValue</var> ones if value proposed by the intMinWidth is not enough.<br />
		<br />
	<b>Return value:</b><br />
		&nbsp;&nbsp;a string value which is entered by user. <var>nil</var> means that user input was cancelled.<br />
	</p>
		<p><b>Example:</b></p>
		<div class="example">
		print(shell.inputbox("Rename", "Enter new file name:", "filename.ext", function(name) return not name:match('[\\/:|*?"&lt;&gt;]') end))
		</div>
	<p class="author">Author: qVaclav</p>
</td></tr>

<tr><td>
	<p class="head">
		<dfn id="getfileattr">getfileattr (strFileName)</dfn>
	</p>
	<p>
	<b>Description:</b><br />
		&nbsp;&nbsp;Get file attributes.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strFileName</dfn> - filename<br />
		<br />
	<b>Return value:</b><br />
		&nbsp;&nbsp;contains file attributes as number<br />
	</p>
		<p><b>Example:</b></p>
		<div class="example">
		local attr = shell.getfileattr("c:\\MSDOS.SYS")<br />
		print(attr)
		</div>
	<p class="author">Authors: Midas, Dmitry Maslov</p>
</td></tr>

<tr><td>
	<p class="head">
		<dfn id="setfileattr">setfileattr (strFileName, intFileAttr)</dfn>
	</p>
	<p>
	<b>Description:</b><br />
		&nbsp;&nbsp;Set file attributes.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strFileName</dfn> - filename<br />
		&nbsp;&nbsp;<dfn>iFileAttr</dfn> - file attributes as number<br />
		<br />
	<b>Return value:</b><br />
		&nbsp;&nbsp;contains <var>true</var> (at successful end) or <var>false</var> (at failure)<br />
	</p>
		<p><b>Example:</b></p>
		<div class="example">
		local result = shell.setfileattr("c:\\MSDOS.SYS", 32)<br />
		if result == true then<br />
		&nbsp;&nbsp;print("File attributes are successfully established")<br />
		else<br />
		&nbsp;&nbsp;print("error")<br />
		end
		</div>
	<p class="author">Authors: Midas, Dmitry Maslov</p>
</td></tr>

<tr><td>
	<p class="head">
		<dfn id="fileexists">fileexists (strFileName)</dfn>
	</p>
	<p>
	<b>Description:</b><br />
		&nbsp;&nbsp;Check exist file or folder with specified name.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strFileName</dfn> - filename or folder name<br />
		<br />
	<b>Return value:</b><br />
		&nbsp;&nbsp;contains <var>true</var> if file (folder) exist or <var>false</var> otherwise<br />
	</p>
		<p><b>Example:</b></p>
		<div class="example">
		local result = shell.fileexists("c:\\MSDOS.SYS")<br />
		if result then<br />
		&nbsp;&nbsp;print("File exist")<br />
		else<br />
		&nbsp;&nbsp;print("File not found")<br />
		end
		</div>
	<p class="author">Author: VladVRO</p>
</td></tr>

<tr><td>
	<p class="head">
		<dfn id="exec">exec (strCommand, [strOperation], [boolNoShow], [bWaitOnReturn])</dfn>
	</p>
	<p>
	<b>Description:</b><br />
		&nbsp;&nbsp;Run external programm or open file with associate application. Allows to execute files, documents and links and to open folders in Windows Explorer.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strCommand</dfn> - filename or folder with possible startup parameters. Can contain <span class="nobr">%environments_variable%</span><br />
		&nbsp;&nbsp;<dfn>strOperation</dfn> - executed operation from listed in the table:<br />
		</p>
		<table style="margin-left:8pt;margin-top:3pt">
		<tr><th>Operation</th><th>Description</th></tr>
		<tr>
		<td align="center">open</td>
		<td>Open. strCommand - filename or folder name (default)</td>
		</tr>
		<tr>
		<td align="center">edit</td>
		<td>Edit. Opens a file for editing. strCommand should be the document.</td>
		</tr>
		<tr>
		<td align="center">print</td>
		<td>Print. strCommand should be the document.</td>
		</tr>
		<tr>
		<td align="center">explore</td>
		<td>Opens a folder in Explorer window (with two panels). strCommand - file or folder</td>
		</tr>
		<tr>
		<td align="center">select</td>
		<td>Opens a folder in Explorer window and chooses the specified folder or a file. strCommand - file or folder</td>
		</tr>
		<tr>
		<td align="center">find</td>
		<td>Showing a dialog box "File Search". strCommand should specify a folder path from which search will begin</td>
		</tr>
		<tr>
		<td align="center">properties</td>
		<td>Showing file|folder "Properties" window. strCommand - file or folder</td>
		</tr>
		<tr>
		<td align="center">other</td>
		<td>Other operation available in context menu of a file. For example "Play" operation available for media files.</td>
		</tr>
		</table>
	<p>
		&nbsp;&nbsp;<dfn>boolNoShow</dfn> - <var>true</var> | <var>false</var> (default) - silent or show a window of the started program<br />
		&nbsp;&nbsp;<dfn>bWaitOnReturn</dfn> - <var>true</var> | <var>false</var> (default) - boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script
		<br />
	<br />
	<b>Return value:</b><br />
		&nbsp;&nbsp;The first contains<br />
		&nbsp;&nbsp;&nbsp;&nbsp;- at successful end: <var>true</var> or (if function has been started with parameter <var>bWaitOnReturn = true</var>), exit code of process<br />
		&nbsp;&nbsp;&nbsp;&nbsp;- at failure: <var>false</var><br />
		&nbsp;&nbsp;The second value contains error/success message of operation;<br />
		&nbsp;&nbsp;or contains the output text of the console application (if execute console applications with parameters <var>boolNoShow = true</var> and <var>bWaitOnReturn = true</var>)
	</p>
		<p><b>Example:</b></p>
		<div class="example">
			-- run application<br />
			shell.exec("clipbrd.exe")<br />
			shell.exec("CMD /c IPCONFIG /all &gt; out.txt", nil, true, false)<br />
			<br />
			-- show result of console application<br />
			print( shell.exec("CMD /c DIR", nil, true, true) )<br />
			print( shell.exec("cscript /nologo %WINDIR%\\system32\\eventquery.vbs /?", nil, true, true) )<br />
			<br />
			-- analysis of the exit code of process<br />
			if shell.exec("ping -n 1 localhost", nil, true, true) == 0 then<br />
			&nbsp;&nbsp;&nbsp;&nbsp;print("Network works") else print("Network does not work")<br />
			end<br />
			<br />
			-- open folder<br />
			shell.exec("%TEMP%")<br />
			shell.exec("%USERPROFILE%", "find")<br />
			shell.exec("%WINDIR%\\regedit.exe", "explore")<br />
			shell.exec("%ProgramFiles%", "properties")<br />
			shell.exec("%ComSpec%", "select")<br />
			<br />
			-- open URL link<br />
			shell.exec("http://scite-ru.org/")<br />
			<br />
			-- send e-mail<br />
			shell.exec("mailto:support@gmail.com")<br />
			<br />
			-- open file (with associate application)<br />
			shell.exec("%WINDIR%\\WindowsUpdate.log")<br />
			<br />
			-- print file<br />
			shell.exec("%WINDIR%\\win.ini", "print")<br />
			<br />
			-- edit file<br />
			shell.exec("%WINDIR%\\winnt.bmp", "edit")
		</div>
	<p class="author">Authors: Dmitry Maslov</p>
</td></tr>

<tr><td>
	<p class="head">
		<dfn id="findfiles">findfiles (strFindMask)</dfn>
	</p>
	<p>
	<b>Description:</b><br />
		&nbsp;&nbsp;Searches for files and folders with mask and returned result as the table.<br />
	<br />
	<b>Parameters:</b><br />
		&nbsp;&nbsp;<dfn>strFindMask</dfn> - file or folder name, or mask with wildcard symbol, which replaces one or several symbols: (<var>?</var>) can present any single symbol; (<var>*</var>) it is used for present of any symbol or group of symbols.<br />
		<br />
	<b>Return value:</b><br />
		&nbsp;&nbsp;Returns the list of the found files and folders as the numbered table (numbering begins with <var>1</var>), where<br />
		&nbsp;&nbsp;each element is structure containing:
	</p>
		<table style="margin-left:8pt;margin-top:3pt;margin-bottom:3pt">
		<tr><th>Value</th><th>Description</th></tr>
		<tr>
			<td align="left">name</td>
			<td>name of a folder or file</td>
		</tr>
		<tr>
			<td align="left">isdirectory</td>
			<td>attribute a file it or a folder (<var>true</var> if a folder, <var>false</var> if a file)</td>
		</tr>
		<tr>
			<td align="left">attributes</td>
			<td>attributes (see lower)</td>
		</tr>
		<tr>
			<td align="left">size</td>
			<td>size of a file in bytes</td>
		</tr>
		</table>
	<p>
		&nbsp;&nbsp;Attributes are submitted as number which can be a combination of the following values:
	</p>
		<table style="margin-left:8pt;margin-top:3pt;margin-right:8pt">
		<tr><th>Value</th><th>Description</th></tr>
		<tr>
			<td>0x00000001</td>
			<td>A file or directory that is read-only. For a file, applications can read the file but cannot write to it or delete it. For a directory, applications cannot delete it, but applications can create and delete files from that directory.</td>
		</tr>
		<tr>
			<td>0x00000002</td>
			<td>A file or directory that is hidden. Files and directories marked with this attribute do not appear in an ordinary directory listing.</td>
		</tr>
		<tr>
			<td>0x00000004</td>
			<td>A file or directory that the operating system uses a part of or uses exclusively.</td>
		</tr>
		<tr>
			<td>0x00000010</td>
			<td>This item is a directory.</td>
		</tr>
		<tr>
			<td>0x00000020</td>
			<td>A file or directory that needs to be archived. Applications use this attribute to mark files for backup or removal.</td>
		</tr>
		<tr>
			<td>0x00000080</td>
			<td>A file or directory that does not have other attributes set.</td>
		</tr>
		<tr>
			<td>0x00000100</td>
			<td>A file that is being used for temporary storage. The operating system may choose to store this file's data in memory rather than on mass storage, writing the data to mass storage only if data remains in the file when the file is closed.</td>
		</tr>
		<tr>
			<td>0x00000200</td>
			<td>A file that is a sparse file.</td>
		</tr>
		<tr>
			<td>0x00000400</td>
			<td>A file or directory that has an associated reparse point.</td>
		</tr>
		<tr>
			<td>0x00000800</td>
			<td>A file or directory that is compressed. For a file, all of the data in the file is compressed. For a directory, compression is the default for newly created files and subdirectories.</td>
		</tr>
		<tr>
			<td>0x00001000</td>
			<td>The data in this file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is hierarchical storage management software.</td>
		</tr>
		<tr>
			<td>0x00002000</td>
			<td>A file or directory that is not indexed by the content indexing service.</td>
		</tr>
		<tr>
			<td>0x00004000</td>
			<td>A file or directory that is encrypted. For a file, all data streams in the file are encrypted. For a directory, encryption is the default for newly created files and subdirectories.</td>
		</tr>
		<tr>
			<td>0x00010000</td>
			<td>This file virtual.</td>
		</tr>
		</table>
	<p>
		&nbsp;&nbsp;At failure return <var>nil</var>
	</p>
		<p><b>Example:</b></p>
		<div class="example">
		local t = shell.findfiles("C:\\*")<br />
		if t then<br />
		&nbsp;&nbsp;table.sort(t,<br />
		&nbsp;&nbsp;&nbsp;&nbsp;function(v1,v2)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if v1.isdirectory ~= v2.isdirectory then<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return v1.isdirectory<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return v1.name:lower() &lt; v2.name:lower()<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />
		&nbsp;&nbsp;&nbsp;&nbsp;end<br />
		&nbsp;&nbsp;)<br />
		&nbsp;&nbsp;table.foreachi(t,<br />
		&nbsp;&nbsp;&nbsp;&nbsp;function(i,v)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if v.isdirectory then<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(string.format("D%5x %s", v.attributes, v.name))<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(string.format(" %5x %-30s", v.attributes, v.name), v.size)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />
		&nbsp;&nbsp;&nbsp;&nbsp;end<br />
		&nbsp;&nbsp;)<br />
		else<br />
		&nbsp;&nbsp;print("not found")<br />
		end<br />
		</div>
	<p class="author">Author: VladVRO</p>
</td></tr>

</table>

<h3>Download</h3>

<p><u>Current version Shell</u>: <var>1.2</var><br /></p>
<p>
<a href="http://scite-ru.googlecode.com/hg/pack/tools/LuaLib/shell.dll">shell.dll</a><br />
<a href="http://scite-ru.googlecode.com/hg/lualib/shell/">Source code</a>
</p>

</body>
</html>
